package com.nkzy.bigeventback.controller;

import com.nkzy.bigeventback.entity.Category;
import com.nkzy.bigeventback.entity.Result;
import com.nkzy.bigeventback.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@CrossOrigin//跨域
@RequestMapping("/category")
public class CategoryController {
    @Autowired
    private CategoryService cs;
    //新增文章分类
    @PostMapping
    public Result addCategoty(@RequestBody Category category){//去请求体中拿参数，如果不加就是空
        cs.addCategory(category);
        return Result.success();//调用静态方法
    }
    //查询文章分类列表
    @GetMapping
    public Result findAllCategory(){
        List<Category> categoryList=cs.findAllCategory();
        return Result.success(categoryList);
    }
    //更新文章分类
    @PutMapping
    public Result modifyCategory(@RequestBody Category category){
        cs.modifyCategory(category);
        return Result.success();
    }
    //删除文章分类
    @DeleteMapping
    public Result removeCategory(Integer id){
        cs.removeCategory(id);
        return Result.success();
    }
}
